﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ATM_Banking_Service.DAO;

namespace ATM_Banking_Service.Service
{
    internal partial class ATM_Manager
    {

        #region Variable

        readonly CustomerDAO _customerDao = new CustomerDAO();
        readonly SercurityDAO _sercurityDao = new SercurityDAO();

        #endregion
        public string Login(string customerId, string pin)
        {
            string token;
            int errorCode;
            bool isSuccess = _customerDao.Login(customerId, pin, out token, out errorCode);
            string result = token + "&" + Convert.ToString(errorCode);
            return result;          
        }

        public bool Logout(string token)
        {
            return _customerDao.Logout(token);
        }

        /**public string Login(string customerId, string pin)
        {
            string token;
            customerDao.Login(customerId, pin);
            sercurityDao.CreateToken(customerId, out token);
            return token;
        }**/

        public int Withdraw(string token, long amount)
        {
            return _customerDao.Withdraw(token, amount);
        }

        public int Deposit(string token, long amount)
        {
            return _customerDao.Deposit(token, amount);
        }

        public int Transfer(string token, string receiverId, long amount)
        {
            return _customerDao.Transfer(token, receiverId, amount);
        }

        public string ShowBalance(string token)
        {
            return _customerDao.ViewBalance(token);
        }

        public string GetError(int errorCode)
        {
            int code = errorCode;
            string errorMessage = "";
            switch(code)
            {
                case 1:
                    errorMessage = "Login Failed! Pin incorrect! Please try again!";
                    break;
                case 2:
                    errorMessage = "Account do not exist!";
                    break;
                case 3:
                    errorMessage = "You enter wrong pin 3 times. This account will be blocked. Please contact the Bank!";
                    break;
                case 4:
                    errorMessage = "This account have been blocked. Please contact the Bank!";
                    break;
                case 5:
                    errorMessage = "The money you want to withdraw was incorrect. It must be multiples of $20.00! Please try again!";
                    break;
                case 6:
                    errorMessage = "You can not withdraw all of money in your account. The money in your account must be at least $50.00 in account! Please try again!";
                    break;
                case 7:
                    errorMessage = "The receiver you want transfer money to does not exist. Please check his/her account ID again!";
                    break;
                case 8:
                    errorMessage = "The money in your account after transfering must be at least $50.00 in account. Please try again!";
                    break;
                case 9:
                    errorMessage = "Transaction was failed because of an unknown error! Please try again later!";
                    break;
                case 10:
                    errorMessage = "The transaction is timeout. Please login again to conduct transaction!";
                    break;
                case 11:
                    errorMessage = "The account was blocked. Please contact the Bank!";
                    break;
            }
            return errorMessage;
        }

        public bool BlockAccount(string id)
        {
            return _customerDao.AccountBlocking(id);
        }
    }
}
